package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.LandmarkDetai;
import cn.wolfcode.trip.base.domain.TicketPayOrderForm;
import cn.wolfcode.trip.base.domain.TicketPayPassword;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.service.ITicketPayOrderFormService;
import cn.wolfcode.trip.base.service.ITicketPayPasswordService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("ticketPayPasswords")
public class TicketPayPasswordController {

    @Autowired
    private ITicketPayPasswordService ticketPayPasswordService;
    @Autowired
    private ITicketPayOrderFormService ticketPayOrderFormService;

    @GetMapping
    public Object getTicketPayPasswords(String passdata,Long userId,Long detailId,Integer caId){
        JSONResult result=new JSONResult();
        TicketPayPassword ticketPayPasswords = ticketPayPasswordService.selectByIdAndPass(userId, passdata);
        if(ticketPayPasswords!=null){
            TicketPayOrderForm ticketPayOrderForm=new TicketPayOrderForm();
            User u=new User();
            u.setId(userId);
            ticketPayOrderForm.setUser(u);
            LandmarkDetai landmarkDetai=new LandmarkDetai();
            landmarkDetai.setId(detailId);
            ticketPayOrderForm.setLandmarkDetai(landmarkDetai);
            ticketPayOrderForm.setState(caId);
            ticketPayOrderFormService.save(ticketPayOrderForm);
            return result;
        }else{
            result.mark("密码错误");
            return result;
        }
    }
}
